package sgd.tp2.api.cmdline;

import java.io.File;
import java.io.IOException;

import com.beust.jcommander.IStringConverter;

public class MetricsFileConverter implements IStringConverter<String> {

	@Override
	public String convert(String value) {

		if (value == null || value.isEmpty())
			return null;

		File file = new File(value);

		if (file.exists())
			file.delete();

		try {
			file.createNewFile();
		} catch (IOException e) {
			return null;
		}

		return (file.exists() && file.canWrite() ? value : null);
	}
}